import tkinter as tk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

class TemperatureFrame(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.figure = Figure(figsize=(10, 6), dpi=100)
        self.ax = self.figure.add_subplot(111)
        # self.ax.rcParams['font.sans-serif'] = ['SimHei']
        # self.ax.rcParams['axes.unicode_minus'] = False
        self.canvas = FigureCanvasTkAgg(self.figure, master=self)
        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        self.months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
        self.temperatures = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]

        self.ax.plot(self.months, self.temperatures, marker='o')
        self.ax.set_title('去年12个月的温度变化图')
        self.ax.set_xlabel('月份')
        self.ax.set_ylabel('温度(°C)')

root = tk.Tk()
frame = TemperatureFrame(master=root)
frame.mainloop()
